

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:untitled/pages/Getx_project/CountController.dart';
import 'package:untitled/pages/Getx_project/CountObsController.dart';

class CountObsMainPage extends StatefulWidget {
  const CountObsMainPage({Key? key}) : super(key: key);

  @override
  State<CountObsMainPage> createState() => _CountObsMainPageState();
}
// Gex 响应编程
class _CountObsMainPageState extends State<CountObsMainPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Gex 响应编程"),
      ),
      backgroundColor: Colors.white,
      body: Container(
        padding: EdgeInsets.all(30),
        width: double.infinity,
        height: double.infinity,
        child: Column(
          children: [
            GetX<CountObsController>(
              init: CountObsController(),
              builder: (CountObsController controller){
                return Text("当前 count的值为 ${controller.getCount}");

              },
            ),
            Obx((){
              return Text("Obx 当前 count的值为 ${Get.find<CountObsController>().getCount}");
            })
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: (){
          Get.find<CountObsController>().addCount();
        },
      ),
    );
    
  }
}